﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.IO;

namespace Klient
{
    public partial class Klient : Form
    {
        public Klient()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            //try
            //{
            //    IPAddress host = IPAddress.Parse("192.168.0.2");
            //    TcpClient tcpclient = new TcpClient();
            //    tcpclient.Connect(host, 2000);
            //    if (tcpclient.Client.Connected)
            //        MessageBox.Show("Połączono z : " + host);
            //    else
            //        MessageBox.Show("Nie połączono ze zdalnym hostem");                    
            //}

            //catch (SocketException se)
            //{

            //    MessageBox.Show("Błąd : " + se.Message);

            //}

            try
            {
                TcpClient tcpclnt = new TcpClient();
                tcpclnt.Connect("192.168.0.2", 8001);
                // use the ipaddress as in the server program
                MessageBox.Show("Connected");

                String str = "dupa";
                Stream stm = tcpclnt.GetStream();

                ASCIIEncoding asen = new ASCIIEncoding();
                byte[] ba = asen.GetBytes(str);
                stm.Write(ba, 0, ba.Length);
                byte[] bb = new byte[100];
                int k = stm.Read(bb, 0, 100);
                string temp = "";
                for (int i = 0; i < k; i++)
                    temp += (Convert.ToChar(bb[i]));
                MessageBox.Show(temp);

                tcpclnt.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error..... " + ex.StackTrace);
            }

        }
    }
}
